using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using mvLibrary;
using mvLibrary.Controls;
using BlueFinity.mvNET.CoreObjects;

namespace mvLibrary.Controls
{
    public partial class mvCheckBox : CheckBox
    {
        #region Campos
        private int _attribute;
        private string _stringChecked = "S";
        private string _stringNotChecked = "N";
        #endregion 
        #region Propiedades
        public int Attribute
        {
            get { return _attribute; }
            set { _attribute = value; }
        }
        public string StringChecked
        {
            get { return _stringChecked; }
            set { _stringChecked = value; }
        }
        public string StringNotChecked
        {
            get { return _stringNotChecked; }
            set { _stringNotChecked = value; }
        }
        
        #endregion propiedades
        public mvCheckBox()
        {
            InitializeComponent();
        }
        //override de metodos
        protected override void OnCheckedChanged(EventArgs e)
        {
            // si no hace check sobre el control, el methodo BaseForm.ValidateControls
            // copia el valor de StringNotChecked en el atributo correspondiente   
            base.OnCheckedChanged(e);
            BaseForm formulario = FindForm() as BaseForm;
            if (formulario == null)
                {
                    return;
                }
            string checkValue = (Checked == true) ? StringChecked : StringNotChecked;
            try
            {
                formulario.Item.setData(Attribute,checkValue);
            }
            catch(mvException mvEx)
            {
                MessageBox.Show(mvEx.Message);
            }
            
        }
        protected override void OnValidating(CancelEventArgs e)
        {
            base.OnValidating(e);
            

        }
    }
}
